<?php

namespace App\Http\Controllers\Api;


use App\Http\Resources\Recommend;
use App\Models\RecommendPosition;
use App\Http\Resources\Recommend as RecommendResource;
use Illuminate\Support\Facades\Input;


class RecommendController extends ApiController
{



    /**
     *
     *
     *
     * @api {get} /positions/:position/recommends 获取推荐的列表
     * @apiName Recommend get recommends
     * @apiGroup Recommend
     *
     *
     * @apiParam {int} position 1=>首页小横幅,2=>首页小标题,3=>首页图片,4=>男频图片,5=>男频小标题,6=>女频图片,7=>女频小标题,8=>男频精品,9=>女频精品
     * @apiParam {String} [limit] 限制的条数
     * @apiParam {String} [page] 当前的页数
     *
     * @apiVersion 1.0.0
     *
     * @apiSampleRequest /api/positions/:position/recommends
     *
     * @apiSuccessExample {json} Success-Response:
     *  {
     *       "data": [
     *           {
     *               "id": 16,
     *               "recommendable_id": "62",
     *               "recommendable_type": "book",
     *               "is_stress": 0,
     *               "cover_url": null,
     *               "description": null,
     *               "created_at": "2017-09-12 11:17:12",
     *               "book": {
     *                   "id": 62,
     *                   "name": "回忆是座荒芜城",
     *                   "cover": "http://ysapi.yanshiwrite.com/api/user/output/59631ba4f2a32.jpg",
     *                   "book_num": "81bb18db12744fb39317ee1ffae9533b",
     *                   "status": 1,
     *                   "introduction": "在过去的日子里，你有没有等待过一个人？\n袁木曾说过一句话:“我在意的是她的人，而非过去。”他等待着一个人，他容忍她的出尔反尔的感情，她最为不堪的家庭，他把他最美好的年华给了她。\n左知是袁木等待的那个人，她却为另一个人为之疯狂。在校园里的最后一个他在的黄昏。\n他问:“你还是不是我女朋友？”\n他为她打人，辍学。最后离开这座城市时。\n“谢谢你来送我离开。”\n付离很早就明白自己是个神奇的人，他喜欢着袁木又喜欢着柚席。\n柚席嫉妒羡慕过左知，她看着自己发胖的身体，后来又在黑夜里迷失自己。她带着袁木走出密林，袁木带着她逃离过去。\n他们把以往描绘成内心的模样，背地里却被现实击伤。\n\n",
     *                   "author": "杌兮",
     *                   "labels": [
     *                       "青春",
     *                       "虐心"
     *                   ],
     *                   "last_chapter": {
     *                       "id": 18136,
     *                       "chapter_num": "6d9f37ab469f4a458491d83c9606707f",
     *                       "name": "第四十一章",
     *                       "create_time": 1502034414,
     *                       "last_modify_time": 1502111037,
     *                       "type": 0,
     *                       "status": 1
     *                   },
     *                   "read_count": 2606,
     *                   "collection_counts": 328,
     *                   "book_type": "青春校园"
     *               }
     *           }
     *       ],
     *       "links": {
     *           "first": "http://yanshi.dev/api/positions/3/recommends?page=1",
     *           "last": "http://yanshi.dev/api/positions/3/recommends?page=4",
     *           "prev": null,
     *           "next": "http://yanshi.dev/api/positions/3/recommends?page=2"
     *       },
     *       "meta": {
     *           "current_page": 1,
     *           "from": 1,
     *           "last_page": 4,
     *           "path": "http://yanshi.dev/api/positions/3/recommends",
     *           "per_page": "1",
     *           "to": 1,
     *           "total": 4
     *       }
     *   }
     *
     */
    public function index(RecommendPosition $position){

        $limit = Input::get('limit') ?: 20;

        $recommends = $position->recommends()->paginate($limit);

        return RecommendResource::collection($recommends);

    }


}
